package com.quartz.test;

import org.apache.log4j.PropertyConfigurator;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.SimpleDateFormat;

/**
 * 执行传参的job
 * Created by Administrator on 2016/12/29.
 */
public class ParamJob implements Job {
    private static String config = System.getProperty("user.dir") + "\\src\\resource\\log4j.properties";
    Logger log = LoggerFactory.getLogger(ParamJob.class);

    /**
     * 计划任务执行内容
     *
     * @throws JobExecutionException
     */
    public void execute(JobExecutionContext context)
            throws JobExecutionException {
        PropertyConfigurator.configure(config); // 读取log4j配置文件

        // 读取参数
        String param1 = (String) context.getJobDetail().getJobDataMap().get("param1");

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        log.info(sdf.format(new java.util.Date()) + " ：" + param1);
    }
}
